// SPDX-FileCopyrightText: 2023-2025 Sangfor Technologies Inc.
// SPDX-License-Identifier: Mulan PSL v2
package com.geniusai.aip.auth.service.impl;

import com.geniusai.aip.auth.domain.EnvoyFilter;
import com.geniusai.aip.auth.service.EnvoyFilterService;
import io.fabric8.kubernetes.client.KubernetesClient;
import io.fabric8.kubernetes.client.dsl.base.CustomResourceDefinitionContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.IOException;

/**
 * @author lp58607
 * @date 2021/11/8
 */
@Service
public class EnvoyFilterServiceImpl implements EnvoyFilterService {

    @Autowired
    private KubernetesClient client;

    @Autowired
    private CustomResourceDefinitionContext envoyFilterContext;

    @Override
    public void createEnvoyFilter(String username, EnvoyFilter envoyFilter) throws IOException {
        client.customResource(envoyFilterContext).create(username, envoyFilter.getEnvoyFilter());
    }

    @Override
    public void deleteEnvoyFilter(String username) throws IOException {
        client.customResource(envoyFilterContext).delete(username);
    }
}
